package com.ruoyi.project.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.domain.ClUser;
import com.ruoyi.project.system.service.IClUserService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 用户认证Controller
 * 
 * @author cenliey
 * @date 2024-05-03
 */
@RestController
@RequestMapping("/authentication/userAuthentication")
public class ClUserController extends BaseController
{
    @Autowired
    private IClUserService clUserService;

    /**
     * 查询用户认证列表
     */
    @PreAuthorize("@ss.hasPermi('authentication:userAuthentication:list')")
    @GetMapping("/list")
    public TableDataInfo list(ClUser clUser)
    {
        startPage();
        List<ClUser> list = clUserService.selectClUserList(clUser);
        return getDataTable(list);
    }

    /**
     * 导出用户认证列表
     */
    @PreAuthorize("@ss.hasPermi('authentication:userAuthentication:export')")
    @Log(title = "用户认证", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ClUser clUser)
    {
        List<ClUser> list = clUserService.selectClUserList(clUser);
        ExcelUtil<ClUser> util = new ExcelUtil<ClUser>(ClUser.class);
        util.exportExcel(response, list, "用户认证数据");
    }

    /**
     * 获取用户认证详细信息
     */
    @PreAuthorize("@ss.hasPermi('authentication:userAuthentication:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return success(clUserService.selectClUserByUserId(userId));
    }

    /**
     * 新增用户认证
     */
    @PreAuthorize("@ss.hasPermi('authentication:userAuthentication:add')")
    @Log(title = "用户认证", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ClUser clUser)
    {
        return toAjax(clUserService.insertClUser(clUser));
    }

    /**
     * 修改用户认证
     */
    @PreAuthorize("@ss.hasPermi('authentication:userAuthentication:edit')")
    @Log(title = "用户认证", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ClUser clUser)
    {
        return toAjax(clUserService.updateClUser(clUser));
    }

    /**
     * 删除用户认证
     */
    @PreAuthorize("@ss.hasPermi('authentication:userAuthentication:remove')")
    @Log(title = "用户认证", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(clUserService.deleteClUserByUserIds(userIds));
    }
}
